package com.netty.pro.netty.nianbao_chaibao;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author xuzn
 * @ClassName: SendMessageEncoder
 * @ProjectName netty-pro
 * @date 2020/3/23/10:46
 */
public class SendMessageEncoder extends MessageToByteEncoder<SendMessage> {

  @Override
  protected void encode(ChannelHandlerContext ctx, SendMessage msg, ByteBuf out) throws Exception {
    System.out.println("SendMessageEncoder de encoder方法被调用");
    out.writeInt(msg.getLen());
    out.writeBytes(msg.getContent());
  }
}
